package com.bawei.monthdemo2207a.month02.view

import android.annotation.SuppressLint
import android.graphics.drawable.Icon
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Home
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
import com.bawei.monthdemo2207a.month02.fuli.FuLiPage
import com.bawei.monthdemo2207a.month02.home.HomePage
import com.bawei.monthdemo2207a.month02.miaowan.MiaoWanPage
import com.bawei.monthdemo2207a.month02.mine.MinePage
import com.bawei.monthdemo2207a.month02.youxiku.YouXiKuPage

/**
 * 作者：赵亮
 * 时间：2024/12/31 11:18
 * 功能：底部导航
 */

data class BottomEntity(val icon: ImageVector, val title: String)

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun MainPage(navController: NavController = rememberNavController()) {

    // 底部导航数据
    val list = listOf(
        BottomEntity(Icons.Default.Home, "首页"),
        BottomEntity(Icons.Default.Home, "秒玩"),
        BottomEntity(Icons.Default.Home, "游戏库"),
        BottomEntity(Icons.Default.Home, "福利"),
        BottomEntity(Icons.Default.Home, "我的"),
    )

    // 底部导航选中
    var selectIndex by remember {
        mutableStateOf(0)
    }

    Scaffold(
        bottomBar = {
            NavigationBar {
                list.forEachIndexed { index, bottomEntity ->
                    NavigationBarItem(
                        selected = selectIndex == index,
                        onClick = { selectIndex = index },
                        label = { Text(bottomEntity.title) },
                        icon = {
                            Icon(
                                imageVector = bottomEntity.icon,
                                contentDescription = null
                            )
                        })
                }
            }
        }
    ) {
        when (selectIndex) {
            0 -> HomePage()
            1 -> MiaoWanPage()
            2 -> YouXiKuPage()
            3 -> FuLiPage(navController)
            4 -> MinePage()
        }
    }
}

@Preview
@Composable
fun MainPagePreview() {
    MainPage()
}

